import { RequestHandler } from "express";
import "reflect-metadata";

export function middleware(middleware: RequestHandler) {
  return function (targetPrototype: any, methodname: string) {
    const middlewares =
      Reflect.getMetadata("middlewares", targetPrototype, methodname) || [];
    middlewares.push(middleware);

    Reflect.defineMetadata(
      "middlewares",
      middlewares,
      targetPrototype,
      methodname
    );
  };
}
